package com.tchhy.mvplibrary.ui.adapter

import android.os.Parcelable
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager

import androidx.fragment.app.FragmentStatePagerAdapter

/**
 * Description FragmentStatePagerAdapter的基类
 *
 * Author: wfy
 *
 * time: 2018/8/22
 *
 */
open class CommonBaseFragmentStatePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {

    private var fragments: MutableList<Fragment>? = null
    private var titles: List<String>? = null


    override fun getItem(position: Int): Fragment {
        return fragments!![position]
    }

    override fun getCount(): Int {
        return fragments?.size ?: 0
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return titles?.get(position) ?: ""
    }

    fun setFragments(fragments: List<Fragment>) {
        this.fragments = fragments.toMutableList()
        notifyDataSetChanged()
    }


    fun setTitles(titles: List<String>) {
        this.titles = titles
        notifyDataSetChanged()
    }


    override fun saveState(): Parcelable? {
        return super.saveState()
    }
}